
package com.huizhan.web.dao;
 
import org.springframework.data.domain.*;
import org.springframework.data.jpa.repository.*;
import org.springframework.stereotype.Repository;
import java.util.*;
import com.huizhan.web.model.*;


@Repository 
public interface ProjectDao extends JpaRepository<Project,String>
{
    /**
     * 根据项目类型ID获取项目集合
     * @param projectTypeId 项目类型ID
     * @return 项目集合
     */
    List<Project> findByProjectTypeId(Long projectTypeId);

    /*
    * 根据名称返回项目
    */
    Project findByName(String name);

    /**
     * 分页查项目集合
     * @param name 名称
     * @param projectTypeId 项目类型ID
     * @param pageable 分页参数
     * @return 用户集合
     */
    @Query(
        value = "SELECT * FROM project"
            + " WHERE (name LIKE CONCAT('%',?1,'%') OR ?1  = '')"
            + " AND (project_Type_Id =?2 OR ?2 = 0) ", 
        countQuery = "SELECT COUNT(1) FROM project"
            + " WHERE (name LIKE CONCAT('%',?1,'%') OR ?1  = '')"
            + " AND (project_Type_Id =?2 OR ?2 = 0 )",
        nativeQuery = true
    )
    Page<Project> findByWhere(String name,Long projectTypeId, Pageable  pageable);
}
